package com.wkq.move.module.main.ui.adapter

import android.content.Context
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.bumptech.glide.request.RequestOptions
import com.wkq.lib_base.adapter.KtDataBindingAdapter
import com.wkq.lib_base.adapter.KtDataBindingViewHolder
import com.wkq.move.R
import com.wkq.move.databinding.ItemDownBtBinding
import com.wkq.net.model.MoveInfo

/**
 *
 * 作者:吴奎庆
 *
 * 时间:2020/5/24
 *
 * 用途:
 */


class MoveDownImgAdapter(context: Context, layoutId: Int) :
    KtDataBindingAdapter<MoveInfo.DownBTInfo>(context, layoutId) {

    override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
        super.onBindViewHolder(holder, position)
        var ktholder = holder as KtDataBindingViewHolder;
        var binding = ktholder.getBinding() as ItemDownBtBinding


        //通过图片加载器实现圆角，你也可以自己使用圆角的imageview，实现圆角的方法很多，自己尝试哈
        val requestOptions =
            RequestOptions.placeholderOf(R.drawable.bg_image_loading)
                .error(R.drawable.bg_image_loading)
                .centerCrop().diskCacheStrategy(DiskCacheStrategy.RESOURCE).dontAnimate()

        Glide.with(holder.itemView)
            .load(getItem(position)?.icon)
            .apply(requestOptions)
            .into(binding.ivDown)

        if (viewClickListener!=null){
            binding.root.setOnClickListener { viewClickListener?.onViewClick(binding.root,getItem(position)) }
        }

    }
}